package general.guicontrols.clusterpanels;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JPanel;

import general.art.CenteredCluster;
import general.art.Link;
import general.art.Node;
import general.guicontrols.layoutmanager.ClusterLayout;
import viewdatabase.ClusterGUI;

public class ClusterDisplay extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final CenteredCluster myCluster;
	private final Map<Node, NodePanel> nodeToButton = new HashMap<Node, NodePanel>();
	private int xOffSet = 0;
	private int yOffSet = 0;

	public ClusterDisplay(CenteredCluster c){

		myCluster = c;

		this.setLayout( new ClusterLayout(nodeToButton, myCluster) );


		//nodeToButton.put(c.getSeedNode(), new NodePanel(c.getSeedNode()));

		for(Node n : c.getNodes()){

			NodePanel b =  new NodePanel(n, null);
			this.add(b);


			System.out.println(n);

			nodeToButton.put(n, b);

		}

	}


	@Override
	public void paint(Graphics g){
		super.paint(g);


		//System.out.println();

		g.setColor(Color.BLACK);

		for(Link l : myCluster.getLinks()){

			Rectangle r1 =	nodeToButton.get(l.getNode1()).getBounds();
			Rectangle r2 =	nodeToButton.get(l.getNode2()).getBounds();

			int x1 = (int) r1.x + (int) r1.width /2;
			int y1 = (int) r1.y + (int) r1.height /2;

			int x2 = (int) r2.x + (int) r2.width / 2;
			int y2 = (int) r2.y + (int) r2.height /2;


			//System.out.println(l.getNode1() + " " + x1 +" " +  y1 + "; "+ l.getNode2() + " " +  x2 +" " +  y2);


			g.drawLine(x1, y1, x2, y2);


		}

	}
	
	public int getXOffSet(){

		return xOffSet;

	}

	public int getYOffSet(){

		return yOffSet;

	}

	public void addXOffSet(int num){


		xOffSet += num;
		this.doLayout();
		this.repaint();
		
	}

	public void addYOffSet(int num){

		yOffSet += num;
		this.doLayout();
		this.repaint();

	}


}
